package com.yu.shortlink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yu.shortlink.admin.common.convention.result.Result;
import com.yu.shortlink.admin.remote.dto.ShortLinkRemoteService;
import com.yu.shortlink.admin.remote.dto.req.ShortLinkAccessRecordReqDTO;
import com.yu.shortlink.admin.remote.dto.req.ShortLinkCreateReqDTO;
import com.yu.shortlink.admin.remote.dto.req.ShortLinkPageReqDTO;
import com.yu.shortlink.admin.remote.dto.resp.ShortLinkCreateRespDTO;
import com.yu.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import com.yu.shortlink.admin.remote.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author yushiwang
 * @Date 2024/5/21 22:35
 * @PackageName:com.yu.shortlink.admin.controller
 * @ClassName: ShortLinkController
 * @Version 1.0
 */

/**
 * 短链接后管
 */
@RestController
public class ShortLinkController {

    /**
     * 后续重构SpringCloud Feign调用
     */
    ShortLinkRemoteService shortLinkRemoteService = new ShortLinkRemoteService() {
    };

    /**
     * 分页查询短链接
     */
    @GetMapping("/api/short-link/admin/v1/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkPageReqDTO requestParam){
        return shortLinkRemoteService.pageShortLink(requestParam);
    }

    @PostMapping("/api/short-link/admin/v1/create")
    public Result<ShortLinkCreateRespDTO> createShortLink(@RequestBody ShortLinkCreateReqDTO requestParam){
        return shortLinkRemoteService.createShortLink(requestParam);
    }

    /**
     * 访问单个短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/admin/v1/access-record")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkAccessRecord(ShortLinkAccessRecordReqDTO requestParam){
        return shortLinkRemoteService.shortLinkAccessRecord(requestParam);
    }


}
